package com.qf.lanzhou.blog.api.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author LEON-HE
 */
public class DruidUtil {

    //声明连接池对象
    private static DataSource dataSource;

    static {
        try {
            //实例化配置
            Properties properties = new Properties();
            InputStream stream = DruidUtil.class.getClassLoader().getResourceAsStream("db.properties");
            properties.load(stream);
            dataSource = DruidDataSourceFactory.createDataSource(properties);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static DataSource getDataSource(){
        return dataSource;
    }
}
